/**
 * Student.java.
 */
package rs.edu.fit.model;

import java.util.ArrayList;
import java.util.List;

import rs.edu.fit.model.interfaces.IWorkingWithExames;

public final class Student implements IWorkingWithExames{
	/** Student first name. */
	private String firstName;
	/** Student last name. */
	private String lastName;
	/** Current year of study. */
	private int yearOfStudy;
	/** Student index number; each student has unique index number. */
	private String indexNumber;
	/** List of exams that student have enrole for exam term. */
	private List<Exam> lExams;

	/** Default constructor. */
	@SuppressWarnings("unused")
	private Student() {

	}

	/**
	 * Constructor with the parameters. It has all the parameters except list
	 * exams, that is creating empty.
	 */
	public Student(String firstName, String lastName, int yearOfStudy,
			String indexNumber) {
		super();
		this.firstName = firstName;
		this.lastName = lastName;
		this.yearOfStudy = yearOfStudy;
		this.indexNumber = indexNumber;
		lExams = new ArrayList<Exam>();
	}

	/** Constructor with all the elements. */
	public Student(final String firstName, final String lastName,
			final int yearOfStudy, final String indexNumber,
			final List<Exam> lExams) {
		super();
		this.firstName = firstName;
		this.lastName = lastName;
		this.yearOfStudy = yearOfStudy;
		this.indexNumber = indexNumber;
		this.lExams = lExams;
	}
	
	/*
	 * (non-Javadoc)
	 * @see rs.edu.fit.model.interfaces.IWorkingWithExames#addExam(rs.edu.fit.model.Exam)
	 */
	public final boolean addExam(final Exam exam) {
		if (!lExams.contains(exam)) {
			lExams.add(exam);
			return true;
		}
		return false;
	}

	/*
	 * (non-Javadoc)
	 * @see rs.edu.fit.model.interfaces.IWorkingWithExames#addMultipleExams(java.util.List)
	 */
	public final void addMultipleExams(final List<Exam> lExamsToAdd) {
		for (Exam exam : lExamsToAdd) {
			lExams.add(exam);
		}
	}
	
	/*
	 * (non-Javadoc)
	 * @see rs.edu.fit.model.interfaces.IWorkingWithExames#removeExam(rs.edu.fit.model.Exam)
	 */
	public final boolean removeExam(final Exam exam) {
		if (lExams.contains(exam)) {
			lExams.remove(exam);
			return true;
		}
		return false;
	}
	
	/*
	 * (non-Javadoc)
	 * @see rs.edu.fit.model.interfaces.IWorkingWithExames#removeAllExams(java.util.List)
	 */
	public final void removeMultipleExams(final List<Exam> lExemsToRemove) {
		for (Exam exem : lExemsToRemove) {
			lExams.remove(exem);
		}
	}

	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(final Object o) {
		if (o instanceof Student) {
			Student std = (Student) o;
			return this.indexNumber.equals(std.getIndexNumber());
		}
		return false;
	}

	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		int result = 37;
		result += indexNumber.hashCode() * 27;

		return result;
	}

	/* Only getters, setters and toString from this point. */

	public final String getFirstName() {
		return firstName;
	}

	public final void setFirstName(final String firstName) {
		this.firstName = firstName;
	}

	public final String getLastName() {
		return lastName;
	}

	public final void setLastName(final String lastName) {
		this.lastName = lastName;
	}

	public final int getYearOfStudy() {
		return yearOfStudy;
	}

	public final void setYearOfStudy(final int yearOfStudy) {
		this.yearOfStudy = yearOfStudy;
	}

	public final String getIndexNumber() {
		return indexNumber;
	}

	public final void setIndexNumber(final String indexNumber) {
		this.indexNumber = indexNumber;
	}

	public final List<Exam> getlExams() {
		return lExams;
	}

	public final void setlExams(List<Exam> lExams) {
		this.lExams = lExams;
	}

	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Student [firstName=" + firstName + ", lastName=" + lastName
				+ ", yearOfStudy=" + yearOfStudy + ", indexNumber="
				+ indexNumber + "]";
	}
}
